package logic

import (
	"cart_srv/cart"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DelGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDelGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelGoodsLogic {
	return &DelGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DelGoodsLogic) DelGoods(req *types.DelGoodsRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	_, err = l.svcCtx.CartRpc.DelGoods(l.ctx, &cart.DelGoodsRequest{
		GoodsId: int64(req.GoodsId),
		UserId:  int64(req.UserId),
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  "删除失败",
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "删除成功",
	}, nil
}
